<?php

namespace app\admin\model\xiluedu;

use think\Exception;
use think\Model;


class SignRule extends Model
{

    

    

    // 表名
    protected $name = 'xiluedu_sign_rule';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];
    
    protected static function init()
    {
        self::beforeWrite(function ($row){
            $query = static::where('day',$row->day);
            if(isset($row->id)){
                $query->where('id','<>',$row->id);
            }
            if($query->find()){
                throw new Exception("连续签到天数不得重复");
            }

        });
    }


}
